/**
 * Created by Chongyi on 2015/10/14 0014.
 */

(function($) {
    'use strict';

    window.AdminTools = {
        csrfToken: '',
        itemDeleteEvent: function(target) {
            var id = target.attr('data-item-id');
            var form = $('<form></form>');
            var method = $('<input>');
            var csrf = $('<input>');

            method.attr('name', '_method');
            method.attr('value', 'DELETE');

            csrf.attr('name', '_token');
            csrf.attr('value', this.csrfToken);

            form.attr('action', target.attr('data-post-url'));
            form.attr('method', 'post');

            form.append(method);
            form.append(csrf);

            form.submit();
        }
    };

    var AdminTools = window.AdminTools;

    $(document).ready(function() {
        /**
         * 数据项删除操作
         */
        $(document).on('click', '.op-delete', function(e) {
            e.preventDefault();

            var me = $(this);

            dialog({
                title: '警告',
                content: '确认删除该项？',
                okValue: '确认',
                ok: function() {
                    AdminTools.itemDeleteEvent(me);
                },
                cancelValue: '取消',
                cancel: function() {
                    return true;
                }
            }).showModal();
        });


    });
})(jQuery);